
// import CONFIG from '/config.js';
import {isLogin} from "@/api/index.js";

const base_url = 'http://10.2.1.33:8080';

const timeout = 50000;

export default (params) => {
	let url = params.url;
	let method = params.method || "get";
	let data = params.data || {};
	
	const userInfo = uni.getStorageSync('userInfo')
	
	let header = {
		'Blade-Auth': uni.getStorageSync('token') || '',
		'Content-Type': 'application/json;charset=UTF-8',
		
		'Cookie':`JSESSIONID=${userInfo?.sessionId}`,
		...params.header
	};
	
	if (method == "post") {
		header = {
			'Content-Type': 'application/json',
			'Cookie':`JSESSIONID=${userInfo?.sessionId}`,
		};
	}


	return new Promise((resolve, reject) => {
		uni.request({
			enableCookie: true,
			url: base_url + url,
			method: method,
			header: header,
			data: data,
			timeout: timeout,
			success(response) {
				resolve(response.data);
				try {
					// if (!userInfo?.sessionId) {
					// 	uni.showModal({
					// 		title: "提示",
					// 		content: "请登录",
					// 		showCancel: false,
					// 		success:() => {
					// 			setTimeout(() => {
					// 				uni.navigateTo({
					// 					url: "/view/login/login",
					// 				});
					// 			}, 1000);
					// 		},
					// 	});
					// 	return false;
					// }
					// resolve(response.data);
				}catch(e) {
					console.log("e", e)
				}
				
			},
			fail(err) {
				reject(err);
			},
			complete() {
				// uni.hideLoading();
			}
		});
	}).catch(() => {});
};